<?php include "../../config.php";?>
<?php include "../../connection.php";?>
<?php session_start(); ?>
<?
//判断是否微信端，分两种情况有id,跳转登陆，微信无id，需要账密绑定登陆
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') == true) {

//有id，1：已经绑定，2：还未绑定。
    if($_REQUEST['openid'])
    {

       $user=select_one_line_all_items($table_Prefix."employee","wechat_openid= '".$_REQUEST['openid']."'");

        //如果有绑定，直接获取登陆信息，写入session；
        if($user['authority']=="是")
        {
        $_SESSION['username']     = $user['name'];
        $_SESSION['department']   = $user['department'];
        $_SESSION['departmentid'] = $user['departmentid'];
        $_SESSION['mid']          = $user['mid'];
        $_SESSION['nid']          = $user['nid'];
        $_SESSION['quanxian']     = $user['quanxian'];
        $_SESSION['position']     = $user['position'];
        $_SESSION['wechat_openid']     = $user['wechat_openid'];

            echo "应该跳转登陆";
            header('Location:../controlbase/');
        }

        //如果没有绑定，hidden这个openid来到登陆绑定,什么都不用做

    }

//没有id，需要跳转获取id
    else
    {
        header('Location:http://wx.enpingshi.com/var_bind.php');
    }

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>用户登陆</title>
    <script type="text/javascript" src="js/viewport.js"></script>
    <link href="css/css.css"      rel="stylesheet" type="text/css"/>

</head>


<body>

<?

if(!isset($_REQUEST['username']) or $_REQUEST['username']=='')
{
	$_REQUEST['username']='';
	$_REQUEST['userpass']='';
}
?>

<div id="width_height">

<div id="help" onclick="help()"><img src="images/help_logo.png"/>帮助</div>

    <script>
        function help(){
            alert('资料收集中！');
        }
    </script>

    <div class="gate_content">
<div id="logo">
<img src="images/logo_m.png" >
<h5>企业资源计划系统</h5>
</div>


<div id="content_form">
<form id="loginform" name="loginform" method="post" action="" enctype="multipart/form-data">
<ul>

    <input type="hidden" name="openid" value="<? echo $_REQUEST['openid'] ?>" />


  <li><label class="icon_1"></label>
    <input type="text" name="username" alt="账号" id="username"  value="<? echo $_REQUEST['username'] ?>" placeholder="账号"/>
  </li>
  <li><label class="icon_2"></label>
    <input type="password" name="userpass" id="userpass" alt=""  value="<? echo $_REQUEST['userpass'] ?>" placeholder="密码" />
  </li>

    <li>
        <input type="text" name="code" id="code" style="float: left;width: 150px;;" alt="验证码"  />

    <img src="../../application/verify/z_imgcode.php" onclick='this.src="../application/verify/z_imgcode.php?"+Math.random();' style="cursor:pointer;height: 50px;width: 150px;">
    </li>
    <?php
    if(isset($_REQUEST['code'])){
        if($_REQUEST['code'] == strtolower($_SESSION['yzm'])){
            echo "
		<script type='text/javascript'>
		document.getElementById('loginform').action = 'logincheck.php';
        document.getElementById('loginform').submit();
		</script>";
        }else{
            echo '<script type="text/javascript"> alert("请输入正确的验证码！");</script>';
        }
    }
    ?>
        <input type="submit" name="submit" id='submit' value="登　陆" />

</ul>
</form>

	<ul id="foger_regist">
<!--	  <li>忘记密码</li>
	  <li>注册登录</li>-->
        <!--<li onclick="bangdingweixin()">绑定微信</li>-->
	</ul>
<script>
    function bangdingweixin(){
        alert("功能准备开发，敬请期待！")
    }
</script>

</div>
    </div>


</div>


<script type="text/javascript">
    (function($) {
        /**
         * 没有开花的树
         * 2012/11/28 15:12
         */

        var placeholderfriend = {
            focus: function(s) {
                s = $(s).hide().prev().show().focus();
                var idValue = s.attr("id");
                if (idValue) {
                    s.attr("id", idValue.replace("placeholderfriend", ""));
                }
                var clsValue = s.attr("class");
                if (clsValue) {
                    s.attr("class", clsValue.replace("placeholderfriend", ""));
                }
            }
        }

        //判断是否支持placeholder
        function isPlaceholer() {
            var input = document.createElement('input');
            return "placeholder" in input;
        }
        //不支持的代码
        if (!isPlaceholer()) {
            $(function() {

                var form = $(this);

                //遍历所有文本框，添加placeholder模拟事件
                var elements = form.find("input[type='text'][placeholder]");
                elements.each(function() {
                    var s = $(this);
                    var pValue = s.attr("placeholder");
                    var sValue = s.val();
                    if (pValue) {
                        if (sValue == '') {
                            s.val(pValue);
                        }
                    }
                });

                elements.focus(function() {
                    var s = $(this);
                    var pValue = s.attr("placeholder");
                    var sValue = s.val();
                    if (sValue && pValue) {
                        if (sValue == pValue) {
                            s.val('');
                        }
                    }
                });

                elements.blur(function() {
                    var s = $(this);
                    var pValue = s.attr("placeholder");
                    var sValue = s.val();
                    if (!sValue) {
                        s.val(pValue);
                    }
                });

                //遍历所有密码框，添加placeholder模拟事件
                var elementsPass = form.find("input[type='password'][placeholder]");
                elementsPass.each(function(i) {
                    var s = $(this);
                    var pValue = s.attr("placeholder");
                    var sValue = s.val();
                    if (pValue) {
                        if (sValue == '') {
                            //DOM不支持type的修改，需要复制密码框属性，生成新的DOM
                            var html = this.outerHTML || "";
                            html = html.replace(/\s*type=(['"])?password\1/gi, " type=text placeholderfriend")
                                .replace(/\s*(?:value|on[a-z]+|name)(=(['"])?\S*\1)?/gi, " ")
                                .replace(/\s*placeholderfriend/, " placeholderfriend value='" + pValue
                                + "' " + "onfocus='placeholderfriendfocus(this);' ");
                            var idValue = s.attr("id");
                            if (idValue) {
                                s.attr("id", idValue + "placeholderfriend");
                            }
                            var clsValue = s.attr("class");
                            if (clsValue) {
                                s.attr("class", clsValue + "placeholderfriend");
                            }
                            s.hide();
                            s.after(html);
                        }
                    }
                });

                elementsPass.blur(function() {
                    var s = $(this);
                    var sValue = s.val();
                    if (sValue == '') {
                        var idValue = s.attr("id");
                        if (idValue) {
                            s.attr("id", idValue + "placeholderfriend");
                        }
                        var clsValue = s.attr("class");
                        if (clsValue) {
                            s.attr("class", clsValue + "placeholderfriend");
                        }
                        s.hide().next().show();
                    }
                });

            });
        }
        window.placeholderfriendfocus = placeholderfriend.focus;
    })(jQuery);


</script>

<script language="javascript" type="text/javascript">

    window.onload = function(){


        function textInputFn(name){
            var o =document.getElementById(name);
            o.setAttribute("valueCache",o.value);

            //失去焦点的时候
            o.onblur = function(){
                if(o.value=="") {
                    document.getElementById(name).setAttribute("placeholder","密码");
                    o.valueCache="";
                    o.value=o.alt;

                } else {
                    o.valueCache=o.value;
                }
            };

            //获得焦点的时候
            o.onfocus = function(){
                document.getElementById(name).setAttribute("placeholder","");
                o.value=o.valueCache;
                var e = event.srcElement;
                var r =e.createTextRange();
                r.moveStart('character',e.value.length);
                r.collapse(true);
                r.select();


            };
            o.onblur();
        }



        textInputFn("username");
        textInputFn("userpass");
        textInputFn("code");

    }
</script>





<canvas id="Mycanvas"></canvas>
<script>
	//定义画布宽高和生成点的个数
	var WIDTH = window.innerWidth, HEIGHT = window.innerHeight;
    if(WIDTH <= 375){
        POINT = 10;
    }else if(WIDTH <= 800){
        POINT = 15;
    }else if(WIDTH <= 1024){
        POINT = 20;
    }else if(WIDTH <= 1400){
        POINT = 25;
    }else{
        POINT = 35;
    }

	var canvas = document.getElementById('Mycanvas');
	canvas.width = WIDTH,
	canvas.height = HEIGHT;
	var context = canvas.getContext('2d');
	context.strokeStyle = 'rgba(0,0,0,0.02)',
	context.strokeWidth = 1,
	context.fillStyle = 'rgba(0,0,0,0.05)';
	var circleArr = [];

	//线条：开始xy坐标，结束xy坐标，线条透明度
	function Line (x, y, _x, _y, o) {
		this.beginX = x,
		this.beginY = y,
		this.closeX = _x,
		this.closeY = _y,
		this.o = o;
	}
	//点：圆心xy坐标，半径，每帧移动xy的距离
	function Circle (x, y, r, moveX, moveY) {
		this.x = x,
		this.y = y,
		this.r = r,
		this.moveX = moveX,
		this.moveY = moveY;
	}
	//生成max和min之间的随机数
	function num (max, _min) {
		var min = arguments[1] || 0;
		return Math.floor(Math.random()*(max-min+1)+min);
	}
	// 绘制原点
	function drawCricle (cxt, x, y, r, moveX, moveY) {
		var circle = new Circle(x, y, r, moveX, moveY)
		cxt.beginPath()
		cxt.arc(circle.x, circle.y, circle.r, 0, 2*Math.PI)
		cxt.closePath()
		cxt.fill();
		return circle;
	}
	//绘制线条
	function drawLine (cxt, x, y, _x, _y, o) {
		var line = new Line(x, y, _x, _y, o)
		cxt.beginPath()
		cxt.strokeStyle = 'rgba(0,0,0,'+ o +')'
		cxt.moveTo(line.beginX, line.beginY)
		cxt.lineTo(line.closeX, line.closeY)
		cxt.closePath()
		cxt.stroke();

	}
	//初始化生成原点
	function init () {
		circleArr = [];
		for (var i = 0; i < POINT; i++) {
			circleArr.push(drawCricle(context, num(WIDTH), num(HEIGHT), num(15, 2), num(10, -10)/40, num(10, -10)/40));
		}
		draw();
	}

	//每帧绘制
	function draw () {
		context.clearRect(0,0,canvas.width, canvas.height);
		for (var i = 0; i < POINT; i++) {
			drawCricle(context, circleArr[i].x, circleArr[i].y, circleArr[i].r);
		}
		for (var i = 0; i < POINT; i++) {
			for (var j = 0; j < POINT; j++) {
				if (i + j < POINT) {
					var A = Math.abs(circleArr[i+j].x - circleArr[i].x),
						B = Math.abs(circleArr[i+j].y - circleArr[i].y);
					var lineLength = Math.sqrt(A*A + B*B);
					var C = 1/lineLength*7-0.009;
					var lineOpacity = C > 0.03 ? 0.03 : C;
					if (lineOpacity > 0) {
						drawLine(context, circleArr[i].x, circleArr[i].y, circleArr[i+j].x, circleArr[i+j].y, lineOpacity);
					}
				}
			}
		}
	}

	//调用执行
	window.onload = function () {
		init();
		setInterval(function () {
			for (var i = 0; i < POINT; i++) {
				var cir = circleArr[i];
				cir.x += cir.moveX;
				cir.y += cir.moveY;
				if (cir.x > WIDTH) cir.x = 0;
				else if (cir.x < 0) cir.x = WIDTH;
				if (cir.y > HEIGHT) cir.y = 0;
				else if (cir.y < 0) cir.y = HEIGHT;
				
			}
			draw();
		}, 16);
	}

</script>




</body>
</html>